package com.kehao.leetcode.jzoffer;

import org.junit.Test;

/**
 * @author Kehao.Chen
 * @version 1.0
 * @date 2022/6/9 13:32
 */
public class JZSolution010 {

    public int subarraySum(int[] nums, int k) {
        int result = 0;
        for (int i = 0; i < nums.length; i++) {
            int sum = nums[i];
            if(sum == k){
                result++;
            }
            for (int j = i+1; j < nums.length; j++) {
                sum+=nums[j];
                if(sum == k){
                    result++;
                }
            }
        }
        return result;
    }

    @Test
    public void test01(){
        int[] nums = {1,1,1};
        int k = 2;
        int result = subarraySum(nums, k);
        System.out.println(result);
    }

    @Test
    public void test02(){
        int[] nums = {1,2,3};
        int k = 3;
        int result = subarraySum(nums, k);
        System.out.println(result);
    }
}
